<?php
include '../../../wp-blog-header.php';
$columns_comment['name'] = $_POST['deal_name'].'_'.strtotime(date("d-m-Y H:i:s"));
$columns_comment['associated_deal'] = $_POST['deal_id'];
$columns_comment['user'] = $_POST['consumer_id'];
$columns_comment['comment'] = pods_sanitize($_POST['comment']);

/* Part where we check if user has 2500 points, so his comments wont be moderated */ 
$user_id = $_POST['consumer_id'];
$deal_id = $_POST['deal_id'];

$points = new Pod('points');
$points->findRecords('id DESC', "1", "user.id = '$user_id'");
while($points->fetchRecord())
{
  $points_id = $points->get_field('id');
  $user_name = $points->get_field('user.name');
  $reg_points = $points->get_field('registration');
  $login_points = $points->get_field('login');
  $comments_points = $points->get_field('comments');
  $deals_points = $points->get_field('deals');
  $like_fb_points = $points->get_field('like_fb');
  $feedback_points = $points->get_field('feedback');
  $vote_points = $points->get_field('vote');
  $referral_points = $points->get_field('referral');
}
$total_points = $reg_points + $login_points + $comments_points + $deals_points + $like_fb_points + $feedback_points + $vote_points + $referral_points;


$columns_comment['approved'] = '0';
/*
if($total_points >= '5000')
{
  $columns_comment['approved'] = '1';
}
else
{
  $columns_comment['approved'] = '0';
}
*/

/* Part where we check if user has 3000 points, so his comments wont be moderated */
$api = new PodAPI();
$comments = new Pod('comment');
$comments->findRecords('id DESC', "1", "user.id = '$user_id' && associated_deal.id = '$deal_id'");
if($comments->getTotalRows() == 0)
{
$columns_points['comments'] = ($comments_points + 50);
$params_points = array('datatype' => 'points', 'tbl_row_id' => $points_id, 'columns' => $columns_points);
$api->save_pod_item($params_points);
  
  if($columns_comment['approved'] == 0)
  {
    echo '<img src="'.get_bloginfo('wpurl').'/wp-content/pfiles/images/success.gif" />&nbsp;Thank You! Your Comment has been Registered, You Gained <b>50</b> Points!<br />The Comment will appear after Moderation!';
  }
  elseif($columns_comment['approved'] == 1)
  {
    echo '<img src="'.get_bloginfo('wpurl').'/wp-content/pfiles/images/success.gif" />&nbsp;Thank You! Your Comment has been Registered, You Gained <b>50</b> Points!';
  }
}
else
{
  if($columns_comment['approved'] == 0)
  {
    echo '<img src="'.get_bloginfo('wpurl').'/wp-content/pfiles/images/success.gif" />&nbsp;Thank You! Your Comment has been Registered,<br />The Comment will appear after Moderation!';
  }
  elseif($columns_comment['approved'] == 1)
  {
    echo '<img src="'.get_bloginfo('wpurl').'/wp-content/pfiles/images/success.gif" />&nbsp;Thank You! Your Comment has been Registered!';
  }
}
$params_comment = array('datatype' => 'comment', 'columns' => $columns_comment);
$api->save_pod_item($params_comment);
?>